#include "HShield.h"
#include "Util.h"
#include "Error.h"

#include <io.h>

BOOL HShield::DownloadMOBYFiles( void )
{
	if( !Util::DownloadFile( MOBY_EHSVC_DLL_DOWNLOAD_URL, Util::GetCurDirectory( ) + "HShield\\ehsvc.dll" ) )
		return Util::PrintReturn< BOOL >( "\t\tFailed to download ehsvc.dll ( MOBY's )!\n", ERROR_FAILED_TO_DOWNLOAD_MOBY_EHSVC_DLL );

	if ( !Util::DownloadFile( MOBY_HSUPDATE_EXE_DOWNLOAD_URL, Util::GetCurDirectory( ) + "HShield\\HSUpdate.exe" ) )
		return Util::PrintReturn< BOOL >( "\t\tFailed to download HSUpdate.exe ( MOBY's )!\n", ERROR_FAILED_TO_DOWNLOAD_MOBY_HSUPDATE_EXE );
	
	return TRUE;
}

BOOL HShield::DownloadOriginalFiles( void )
{
	if( !Util::DownloadFile( ORIGINAL_EHSVC_DLL_DOWNLOAD_URL, Util::GetCurDirectory( ) + "HShield\\ehsvc.dll" ) )
		return Util::PrintReturn< BOOL >( "\t\tFailed to download ehsvc.dll ( original )!\n", ERROR_FAILED_TO_DOWNLOAD_ORIGINAL_EHSVC_DLL );

	if ( !Util::DownloadFile( ORIGINAL_HSUPDATE_EXE_DOWNLOAD_URL, Util::GetCurDirectory( ) + "HShield\\HSUpdate.exe" ) )
		return Util::PrintReturn< BOOL >( "\t\tFailed to download HSUpdate.exe ( original )!\n", ERROR_FAILED_TO_DOWNLOAD_ORIGINAL_HSUPDATE_EXE );
	
	return TRUE;
}

BOOL HShield::DeleteFiles( void )
{
	if( _access( std::string( Util::GetCurDirectory( ) + "HShield\\ehsvc.dll" ).c_str( ), 0 ) != -1 )
		if( !DeleteFile( std::string( Util::GetCurDirectory( ) + "HShield\\ehsvc.dll" ).c_str( ) ) )
			return ERROR_FAILED_TO_DELETE_EHSVC_DLL;

	if( _access( std::string( Util::GetCurDirectory( ) + "HShield\\HSUpdate.exe" ).c_str( ), 0 ) != -1 )
		if( !DeleteFile( std::string( Util::GetCurDirectory( ) + "HShield\\HSUpdate.exe" ).c_str( ) ) )
			return ERROR_FAILED_TO_DELETE_HSUPDATE_EXE;

	if( _access( std::string( Util::GetCurDirectory( ) + "HShield\\hshield.log" ).c_str( ), 0 ) != -1 )
		if( !DeleteFile( std::string( Util::GetCurDirectory( ) + "HShield\\hshield.log" ).c_str( ) ) )
			return ERROR_FAILED_TO_DELETE_HSHIELD_LOG;
	
	return TRUE;
}